#include "OiPCH.hpp"
#include "View/OiPixmap.hpp"
#include "OiCropCommand.hpp"

namespace Oi
{
    namespace PLScannerCore
    {
        class CropCommandImpl : public Impl<CropCommand>
        {
        public:
            QImage _pixmap;
            Core::RangeMapPtr _rm;
            Core::PointMapPtr _pm;
        };

        CropCommand::CropCommand()
        {
            OI_I(CropCommand);

            d->_pixmap = ImageViewer::OiImageViewer()->pixmap()->pixmap();
            d->_pm = ImageViewer::OiImageViewer()->pointMap();
            d->_rm = ImageViewer::OiImageViewer()->rangeMap();

        }

        CropCommand::~CropCommand()
        {
            OI_E(CropCommand);
        }

        void CropCommand::reto()
        {
            OI_F(CropCommand);

            if (d->_pm)
            {
                ImageViewer::OiImageViewer()->display(d->_pm);
            }
            else if (d->_rm)
            {
                ImageViewer::OiImageViewer()->display(d->_rm);
            }
            else if (!d->_pixmap.isNull())
            {
                ImageViewer::OiImageViewer()->display(d->_pixmap);
            }
            else
            {
                return;
            }

            ImageViewer::OiImageViewer()->zoomFit();
            BalanceCommand::reto();

        }

    }
}